package com.easidea.tim.service.finance;

import java.sql.CallableStatement;
import java.sql.Connection;

import org.apache.log4j.Logger;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.easidea.tim.dao.finance.AccountAgeReportDao;

public class CustomerAccountAgeReportJob {
	private AccountAgeReportDao accountAgeReportDao;
	private final static Logger log = Logger.getLogger(CustomerAccountAgeReportJob.class);

	/**
	 * 处理报表生成
	 */
	public void processAccountAgeReport(){
		if(accountAgeReportDao != null){
			accountAgeReportDao.getHibernateTemplate().execute(new HibernateCallback() { 
                public Object doInHibernate(Session session) { 
                    try { 
                    	log.info("start customer account age report generation ~!");
                    	long t = System.currentTimeMillis();
                        Connection conn = session.connection(); 
                        String sql = "{call sp_genFinanceAccountAgeReport()}"; 
                        CallableStatement stmt = conn.prepareCall(sql); 
                        stmt.execute(); 
                        log.info("completed account age report process, elapsed : " + (System.currentTimeMillis() - t)/1000 + " seconds ~~!");
                    } catch (Exception e) { 
                    	log.error("process customer account age report failure : "+e.getMessage(), e);
                    }
                    return null; 
                } 
            }); 
		}
	}
	
	/**
	 * @return the accountAgeReportDao
	 */
	public AccountAgeReportDao getAccountAgeReportDao() {
		return accountAgeReportDao;
	}

	/**
	 * @param accountAgeReportDao the accountAgeReportDao to set
	 */
	public void setAccountAgeReportDao(AccountAgeReportDao accountAgeReportDao) {
		this.accountAgeReportDao = accountAgeReportDao;
	}
	
	

}
